package view
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ShowDetail extends Sprite
	{
		private var url:String;
		private var addalpha:Number = 0.1;
		private var imgcontainer:Sprite;
		[Embed(source="assets/tip/round_delete.png")]
		private var closeCls:Class;
		
		private var closeBitmap:Bitmap;
		private var closeSprite:Sprite;
		public function ShowDetail()
		{
			draw();
			this.alpha = 0;
			imgcontainer = new Sprite;
			this.addChild(imgcontainer);
			imgcontainer.x = 10;
			imgcontainer.y = 10;
			closeSprite = new Sprite;
			closeBitmap = new closeCls;
			closeSprite.addChild(closeBitmap);
			closeSprite.x = 680;
			closeSprite.y = 5;
			this.addChild(closeSprite);
			closeSprite.buttonMode = true;
			closeSprite.addEventListener(MouseEvent.CLICK,onClose);
		}
		private function draw():void{//705,355
			graphics.beginFill(0x000000,0.5);
			graphics.drawRoundRect(0,0,705,355,20,20);
			graphics.endFill();
		}
		public function show(url:String):void{
			if(imgcontainer.numChildren){
				imgcontainer.removeChildAt(0);
			}
			this.url = url;
			var img:DetailImg = new DetailImg(false);
			img.setSource(url);
			addalpha = 0.1;
			img.maxH = 335;
			img.maxW = 685;
			imgcontainer.addChild(img);
			this.addEventListener(Event.ENTER_FRAME,onenFrame);
		}
		private function onClose(event:MouseEvent):void{
			addalpha = -0.1;
			this.addEventListener(Event.ENTER_FRAME,onenFrame);
		}
		private function onenFrame(event:Event):void{
			this.alpha += addalpha;
			if(this.alpha >= 1){
				this.removeEventListener(Event.ENTER_FRAME,onenFrame);
			}else if(this.alpha <= 0){
				this.removeEventListener(Event.ENTER_FRAME,onenFrame);
				if(this.parent){
					this.parent.removeChild(this);
				}
			}
		}
	}
}